/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/controls/DropDownList.cpp,v 1.5 2003/11/21 12:39:24 itsme Exp $
 *
 *
 * this module contains some utilities to manage dropdownlists
 * ( load contents from a dictionary, and read result )
 */

#include "DropDownList.h"
#include "debug.h"

void LoadDropDown(CComboBox& combo, const IntegerStringMap& items, int selected)
{
    int selectindex=0;  // default to first item selected

    combo.ResetContent();
    for (IntegerStringMap::const_iterator i= items.begin() ; i!=items.end() ; ++i)
    {
        int index= combo.AddString(ToWString((*i).second.c_str()).c_str());
        combo.SetItemData(index, (*i).first);

        if (selected==(*i).first)
            selectindex= index;
    }
    combo.SetCurSel(selectindex);
}

int GetDropDownValue(CComboBox& combo)
{
    int selectindex= combo.GetCurSel();

    if (selectindex==CB_ERR)
        selectindex= 0; // default to first item selected

    debug("combo result: idx=%d  val=%d\n", selectindex, combo.GetItemData(selectindex));
    return combo.GetItemData(selectindex);
}
